package gwtmodule1.client.gui.stock;

import gwtmodule1.client.gui.utils.DekoTable;
import gwtmodule1.client.gui.utils.FrameClient;
import gwtmodule1.client.gui.utils.FrameProvider;
import gwtmodule1.client.gui.utils.SwitchPage;
import gwtmodule1.client.gui.utils.Title;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class PageEditItemList extends VerticalPanel implements FrameClient {

	private class EditItemTable extends DekoTable {

		public EditItemTable() {
			super();
			addTitle("Brand");
			addTitle("Product");
			addTitle("Available");
			addTitle("");
			addTitleWidget(new Button("add"));
		}

		public void addItem(int id, String brand, String product, int available) {
			Hyperlink edit = new Hyperlink("edit", "EditItem" + id);
			edit.addClickListener(new SwitchPage(provider, pageEditItem));
			AddRow r = addRow();
			r.add(brand);
			r.add(product);
			r.add(available);
			r.add(edit);
			r.add(new Button("delete"));
		}
	}

	private Widget createTable() {
		EditItemTable table = new EditItemTable();
		table.addItem(0, "Microsoft", "XBox", 34);
		table.addItem(1, "Sony", "Playstation 3", 4);
		table.addItem(2, "Nintendo", "Wii", 44);
		table.addItem(3, "Apple", "iPhone", 554);
		return table;
	}

	private FrameProvider provider;

	private PageEditItem pageEditItem = new PageEditItem();

	private Title title;

	public PageEditItemList(FrameProvider provider) {
		super();
		this.provider = provider;
		add(title = new Title("Items"));
		add(createTable());
	}

	public static class ItemListParams {
		private int id;

		private String name;

		public ItemListParams(int id, String name) {
			super();
			this.id = id;
			this.name = name;
		}
	}

	public void onShow(Object param) {
		ItemListParams p = (ItemListParams) param;
		title.setTitle("Items of Subcategory " + p.name);
	}
}
